package no.uib.kwikktaim.gui;

import java.awt.BorderLayout;
import java.awt.event.*;

import javax.swing.JFrame;

/**
 * Our fullscreen implimentation
 */
public class FullScreenMode extends JFrame {

	MainWindow mw;
	MediaViewer mv;

	public FullScreenMode(MediaViewer mv, MainWindow mw) {
		this.setLayout(new BorderLayout());
		this.mw = mw;
		this.mv = mv;
		this.add(mv, BorderLayout.CENTER);
		this.setUndecorated(true);
		this.setExtendedState(JFrame.MAXIMIZED_BOTH);
		this.setVisible(true);
		this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		this.addKeyListener(new Key(this));
	}

	@Override
	public void dispose() {
		mw.setPlayer(mv);
		mw.getPlayer().reloadVideo();
		this.setVisible(false);
	}
}

/**
 * Just a class that tries to hear ESC
 */
class Key implements KeyListener {

	FullScreenMode fs;

	Key(FullScreenMode f) {
		fs = f;
	}

	public void keyReleased(KeyEvent e) {}
	public void keyTyped(KeyEvent e) {}

	public void keyPressed(KeyEvent e) {
		if(e.getKeyCode() == e.VK_ESCAPE)
			fs.dispose();
	}
}
